﻿using log4net;
using log4net.Appender;
using MiniFox.Configurations;
using MiniFox.Data;
using MiniFox.Data.Configurations;
using MiniFox.Log.Configurations;
using System;

namespace MiniFox.Log
{
    /// <summary>
    /// 
    /// </summary>
    public class Logger : ILogger
    {
        const string LOG_INFO = "MINIFOX_LOG_INFO";
        const string LOG_WARN = "MINIFOX_LOG_WARN";
        const string LOG_ERROR = "MINIFOX_LOG_ERROR";
        const string LOG_FATAL = "MINIFOX_LOG_FATAL";

        string _info;
        string _error;
        string _warn;
        string _fatal;

        /// <summary>
        /// 
        /// </summary>
        public Logger()
        {
            _info = LOG_INFO;
            _error = LOG_ERROR;
            _warn = LOG_WARN;
            _fatal = LOG_FATAL;
        }
        /// <summary>
        /// 
        /// </summary>
        protected internal Logger(ILoggerSetting setting)
        {
            _info = setting.Info;
            _error = setting.Error;
            _warn = setting.Warn;
            _fatal = setting.Fatal;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="content"></param>
        public virtual void WriteWarn(LogContent content)
        {
            try
            {
                ILog log = LogManager.GetLogger(_warn);
                log.Warn(content, content.Exception);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            finally
            {

            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="content"></param>
        public virtual void WriteFatal(LogContent content)
        {
            try
            {
                ILog log = LogManager.GetLogger(_fatal);

                log.Fatal(content, content.Exception);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            finally
            {

            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="content"></param>
        public virtual void WriteError(LogContent content)
        {
            try
            {
                ILog log = LogManager.GetLogger(_error);

                log.Error(content, content.Exception);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            finally
            {

            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="content"></param>
        public virtual void WriteInfo(LogContent content)
        {
            try
            {
                ILog log = LogManager.GetLogger(_info);
                log.Info(content, content.Exception);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            finally
            {

            }
        }
        
    }

}
